package 差分;/**
 * @author： li
 * @date： 2022-04-04 13:20
 * @version 1.0
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.*;
public class 绝世武功1 {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    public static void main(String[] args) throws IOException {
        in.nextToken();
        int n =(int)in.nval;
        in.nextToken();
        int m =(int)in.nval;
        long sum=0;
        long[] c=new long[n+10];
        while(m>0){
            in.nextToken();int l =(int)in.nval;
            in.nextToken();int r =(int)in.nval;
            in.nextToken();int s =(int)in.nval;
            in.nextToken();int e =(int)in.nval;
            int d=(e-s)/(r-l);
            c[l]=c[l]+s;//K大佬上面写了
            c[l+1]=c[l+1]+d-s;
            c[r+1]=c[r+1]-d-e;
            c[r+2]=c[r+2]+e;
            m--;
        }
        for(int i=1;i<=n;i++)
            c[i]+=c[i-1];
        for(int i=1;i<=n;i++){
            c[i]+=c[i-1];
            sum+=c[i];
        }
        System.out.println(sum);
    }
}